package com.cch.examSystem.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cch.examSystem.entity.KnowledgeList;
import com.cch.examSystem.entity.MajorList;
import com.cch.examSystem.entity.SubjectList;

public class CategoryListServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		Date now = new Date();
		SimpleDateFormat datetime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat time = new SimpleDateFormat("HH:mm");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();

		String method = request.getParameter("method");
		switch (method) {
		case "major":
			List majorList = new ArrayList();
			MajorList major;
			major = new MajorList("软件工程", "管理员1", datetime.format(now));
			majorList.add(major);
			major = new MajorList("网络工程", "管理员1", datetime.format(now));
			majorList.add(major);
			major = new MajorList("土木工程", "管理员1", datetime.format(now));
			majorList.add(major);
			major = new MajorList("历史师范", "管理员1", datetime.format(now));
			majorList.add(major);
			/* System.out.println(JSON.toJSONString(scaleList)); */
			request.setAttribute("majorList", majorList);
			request.getRequestDispatcher("./manager/majorList.jsp").forward(
					request, response);
			break;
		case "subject":
			List subjectList = new ArrayList();
			SubjectList subject;
			subject = new SubjectList("软件工程", "JAVA基础", "管理员1",
					datetime.format(now));
			subjectList.add(subject);
			subject = new SubjectList("软件工程", "计算机导论", "管理员1",
					datetime.format(now));
			subjectList.add(subject);
			subject = new SubjectList("软件工程", "数据结构", "管理员1",
					datetime.format(now));
			subjectList.add(subject);
			subject = new SubjectList("软件工程", "数据库概论", "管理员1",
					datetime.format(now));
			subjectList.add(subject);
			request.setAttribute("subjectList", subjectList);
			request.getRequestDispatcher("./manager/subjectList.jsp").forward(
					request, response);
			break;
		case "knowledge":
			List knowledgeList = new ArrayList();
			KnowledgeList knowledge;
			knowledge = new KnowledgeList("软件工程", "JAVA基础", "JDBC", "管理员1",
					datetime.format(now));
			knowledgeList.add(knowledge);
			knowledge = new KnowledgeList("软件工程", "JAVA基础", "反射", "管理员1",
					datetime.format(now));
			knowledgeList.add(knowledge);
			knowledge = new KnowledgeList("软件工程", "JAVA基础", "单利模式", "管理员1",
					datetime.format(now));
			knowledgeList.add(knowledge);
			knowledge = new KnowledgeList("软件工程", "JAVA基础", "多态", "管理员1",
					datetime.format(now));
			knowledgeList.add(knowledge);
			request.setAttribute("knowledgeList", knowledgeList);
			request.getRequestDispatcher("./manager/knowledgeList.jsp")
					.forward(request, response);
			break;
		}

		out.flush();
		out.close();
	}
}
